﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MMOG
{
    public partial class ServerGUI : Form
    {
        public ServerGUI()
        {
            InitializeComponent();
        }

        private void quitButton_Click(object sender, EventArgs e)
        {
            Server.exited = true;
            Database.close();
            Application.Exit();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            int total = ++Server.runningTime;
            int h = total/3600;
            int m = (total%3600)/60;
            int s = total%60;
            timeLabel.Text = h + ":" + m + ":" + s;
            userLabel.Text = Server.userOnline.ToString();
        }

        private void ServerGUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            Server.exited = true;
            Database.close();
            Application.Exit();
        }

        private void minimizeButton_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            logBox.Clear();
        }

        private void saveButon_Click(object sender, EventArgs e)
        {
            logBox.SaveFile("log.txt",RichTextBoxStreamType.PlainText);
            Server.addLog("Log data was saved in 'log.txt' file.",MessageType.System);
        }

        private void debugBox_CheckedChanged(object sender, EventArgs e)
        {
            if (debugBox.Checked) Server.addLog("Debug mode enabled!",MessageType.System);
            else Server.addLog("Debug mode disabled!",MessageType.System);
            Server.debugMode = debugBox.Checked;
        }

        private void errorBox_CheckedChanged(object sender, EventArgs e)
        {
            if (errorBox.Checked) Server.addLog("Error only mode enabled!",MessageType.System);
            else Server.addLog("Error only mode disabled!",MessageType.System);
            Server.errorMode = errorBox.Checked;
        }

        private void logBox_TextChanged(object sender, EventArgs e)
        {
            logBox.ScrollToCaret();
        }

        private void messageButton_Click(object sender, EventArgs e)
        {
            InputBox box = new InputBox();
            box.destination.Text = "";
            box.ShowDialog();
            if (box.sent) CoreHandler.sendChat(box.destination.Text, "Admin: " + box.textBox.Text);
            box.Dispose();
        }

        private void popupButton_Click(object sender, EventArgs e)
        {
            InputBox box = new InputBox();
            box.destination.Text = "All";
            box.destination.Enabled = false;
            box.ShowDialog();
            if (box.sent) CoreHandler.sendPopup(null, "Announcement: " + box.textBox.Text);
            box.Dispose();
        }

        private void AnnounceButton_Click(object sender, EventArgs e)
        {
            InputBox box = new InputBox();
            box.destination.Text = "All";
            box.destination.Enabled = false;
            box.ShowDialog();
            if (box.sent) CoreHandler.sendChat(null, "Admin: " + box.textBox.Text);
            box.Dispose();
        }

        private void kickButton_Click(object sender, EventArgs e)
        {
            InputBox box = new InputBox();
            box.destination.Text = "";
            box.ShowDialog();
            if (box.sent) CoreHandler.sendKick(box.destination.Text, "You are kicked because of the following reason: " + box.textBox.Text);
            box.Dispose();
        }

    }
}
